package org.jfonia.connect5.basics;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author wijnand.schepens@hogent.be
 */
public class BasicNode implements Node
{
	protected Set<Observer> observers = new LinkedHashSet<Observer>();

	public void addObserver(Observer o)
	{
		if (!observers.contains(o))
			observers.add(o);
	}

	public boolean containsObserver(Observer o)
	{
		return observers.contains(o);
	}

	public void removeObserver(Observer o)
	{
		observers.remove(o);
	}

	public void notifyObservers()
	{
		for (Observer o: observers)
			o.onNotify(this);
	}

	public void notifyObserversExcept(Observer except)
	{
		for (Observer o: observers)
			if (o != except)
				o.onNotify(this);
	}
}
